# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgbase=lief
pkgname=('lief' 'python-lief')
_pkgname=LIEF
pkgver=0.15.1
pkgrel=2
pkgdesc='Library to instrument executable formats.'
groups=('blackarch' 'blackarch-disassembler' 'blackarch-reversing')
arch=('x86_64')
url='https://github.com/lief-project/lief'
license=('Apache-2.0')
depends=('tl-expected')
makedepends=('cmake' 'python' 'nlohmann-json' 'python-build' 'python-installer'
             'python-wheel' 'python-tomli' 'python-scikit-build-core' 'ninja'
             'python-cattrs' 'python-packaging' 'python-rich'
             'python-setuptools' 'python-pydantic' 'python-pydantic-core'
             'python-pyproject-metadata' 'python-pathspec')
provides=('libLIEF.so')
source=("https://github.com/lief-project/lief/archive/refs/tags/$pkgver.tar.gz")
sha512sums=('30f248ce5c77993ccc08a360bfd74562ff1e661233abf7e6017cd11351ee359c67848a1ac4159b82a38e971f41704a6008b8778c817e06ef558efe21b76e04ae')

prepare() {
  cd "$_pkgname-$pkgver/api/python"

  sed -i 's/==.*//' build-requirements.txt
}

build() {
  cd "$_pkgname-$pkgver"

  cmake \
    -B build \
    -G Ninja \
    -D CMAKE_BUILD_TYPE=Release \
    -D BUILD_SHARED_LIBS=ON \
    -D LIEF_EXAMPLES=OFF \
    -D LIEF_PYTHON_API=ON \
    -D LIEF_OPT_NLOHMANN_JSON_EXTERNAL=ON \
    -D LIEF_OPT_EXTERNAL_EXPECTED=ON
  cmake --build build

  cd api/python
  python -m build --wheel --no-isolation
}

package_lief() {
  cd "$_pkgname-$pkgver"

  DESTDIR="$pkgdir" cmake --install build
}

package_python-lief() {
  depends+=('python' 'lief')

  cd "$_pkgname-$pkgver/api/python"

  python -m installer --destdir="$pkgdir" dist/*.whl
}

